package com.thm.tfast.core.task.job;

import com.thm.tfast.core.task.base.AbstractTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @ClassName SimpleTask
 * @Author THM
 * @Date 2022/11/2 9:05
 * @Version 1.0
 * @Description
 */
@Slf4j
@Component
public class SimpleTask extends AbstractTask {


    @Override
    @PostConstruct
    public void init() {
        register(this);
    }

    @Override
    @Scheduled(cron = "0/5 * * * * ?")
    public void execute() {
        try {
            log.info("简单的定时任务！！！！");
            status = 1;
        } catch (Exception e){
            status = 2;
            log.error("任务运行异常，e={}",e.getMessage());
        }
    }

    @Override
    public String getTaskName() {
        return SimpleTask.class.getSimpleName();
    }

    @Override
    public String getDesc() {
        return "示例定时任务";
    }

    @Override
    public Integer getStatus() {
        return status;
    }
}
